//package com.dykj.fireFighting.web.mq.consumer;
//
//import com.dykj.fireFighting.web.mq.consumer.business.BusinessProcess;
//import lombok.Data;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
//import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
//import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
//import org.apache.rocketmq.common.message.Message;
//import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
///**
// * @Author fgc
// * @Date 2021/9/27 10:13
// * @ Description：消费者配置类
// */
//@Configuration
//@Data
//public class ConsumerConfig {
////    public static final Logger LOGGER = LoggerFactory.getLogger(ConsumerConfig.class);
////    @Value("${rocketmq.consumer.namesrvAddr}")
////    private String namesrvAddr;
////    @Value("${rocketmq.consumer.groupName}")
////    private String groupName;
////    @Value("${rocketmq.consumer.consumeThreadMin}")
////    private int consumeThreadMin;
////    @Value("${rocketmq.consumer.consumeThreadMax}")
////    private int consumeThreadMax;
////    @Value("${rocketmq.consumer.topic}")
////    private String topic;
////    @Value("${rocketmq.consumer.consumeMessageBatchMaxSize}")
////    private int consumeMessageBatchMaxSize;
////
////    @Bean
////    public DefaultMQPushConsumer getRocketMQConsumer() throws Exception {
////
////        if (StringUtils.isEmpty(groupName)){
////            throw new Exception();
////        }
////        if (StringUtils.isEmpty(namesrvAddr)){
////            throw new Exception();        }
////        if(StringUtils.isEmpty(topic)){
////            throw new Exception();
////        }
////        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(groupName);
////        consumer.setNamesrvAddr(namesrvAddr);
////        consumer.setConsumeThreadMin(consumeThreadMin);
////        consumer.setConsumeThreadMax(consumeThreadMax);
////        /**
////         * 设置Consumer第一次启动是从队列头部开始消费还是队列尾部开始消费
////         * 如果非第一次启动，那么按照上次消费的位置继续消费
////         */
////        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
////        /**
////         * 设置消费模型，集群还是广播，默认为集群
////         */
////        consumer.setMessageModel(MessageModel.CLUSTERING);
////        /**
////         * 设置一次消费消息的条数，默认为1条
////         */
////        consumer.setConsumeMessageBatchMaxSize(consumeMessageBatchMaxSize);
////        try {
////            /**
////             * 设置该消费者订阅的主题和tag，如果是订阅该主题下的所有tag，则tag使用*；如果需要指定订阅该主题下的某些tag，则使用||分割，例如tag1||tag2||tag3
////             */
////                consumer.subscribe(topic,"*");
////
////            // 开启内部类实现监听
////            consumer.registerMessageListener((MessageListenerConcurrently) (msg, context) -> {
////                try {
////                    Message message = msg.get(0);
////                    System.out.printf("%s Receive New Messages: %s %n",
////                            Thread.currentThread().getName(), new String(msg.get(0).getBody()));
////                    //主题
////                    String topic = message.getTopic();
////                    //消息内容
////                    String body = null;
////                    body = new String(message.getBody(), "utf-8");
////                    //二级分类
////                    String tags = message.getTags();
////                    //键
////                    String keys = message.getKeys();
////                    System.out.println("topic=" + topic + ", tags=" + tags + ", keys=" + keys + ", msg=" + body);
////                    BusinessProcess businessProcess = BusinessContext.getObject(tags);
////                    ConsumeConcurrentlyStatus process = businessProcess.process(message);
////                    return process;
////                } catch (Exception e) {
////                    e.printStackTrace();
////                    return ConsumeConcurrentlyStatus.RECONSUME_LATER;
////                }
////
////            });
////
////
////            consumer.start();
////            LOGGER.info("consumer is start !!! groupName:{},topics:{},namesrvAddr:{}",groupName,topic,namesrvAddr);
////        }catch (Exception e){
////            LOGGER.error("consumer is start !!! groupName:{},topics:{},namesrvAddr:{}",groupName,topic,namesrvAddr,e);
////            throw new Exception(e);
////        }
////        return consumer;
////    }
//
//}
